/* 
 * Licensed Materials - Property of IBM
 * (c) Copyright IBM Corporation 2010. All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:  Use,
 * duplication or disclosure restricted by GSA ADP Schedule
 * Contract with IBM Corp.
 *
 * This code is released under the terms of the Eclipse Public License
 * version 1.0 which can be found at the top level of this project or
 * or at http://www.eclipse.org/org/documents/epl-v10.php
 */

package com.ibm.mining.model;

import java.io.PrintStream;
import java.util.LinkedList;
import java.util.List;

import com.ibm.mining.Util;

public class Property {
	String name;
	ModelClass modelClass;
	Type type;
	String desc;
	boolean key = false;
	boolean visited = false;
	boolean tracked = false;
	Property reference = null;
	
	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public boolean isTracked() {
		return tracked;
	}

	public void setTracked(boolean tracked) {
		this.tracked = tracked;
	}

	public Property(String name, ModelClass modelClass) {
		this.name = name;
		this.modelClass = modelClass;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public ModelClass getModelClass() {
		return modelClass;
	}

	public void setModelClass(ModelClass modelClass) {
		this.modelClass = modelClass;
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	public String getDescription() {
		return desc;
	}

	public void setDescription(String desc) {
		this.desc = desc;
	}

	public boolean isKey() {
		return key;
	}

	public void setKey(boolean key) {
		this.key = key;
	}
	
	public boolean isVisited() {
		return visited;
	}

	public void setVisited(boolean visited) {
		this.visited = visited;
	}
	
	/**
	 * Get the foreign key that this element should point to
	 * 
	 * @return the property that this property references
	 */
	public Property getReference() {
		return reference;
	}
	
	/**
	 * Sets the Foreign Key for an object.  Basically, if a property is really
	 * a foreign key it should be set here
	 * 
	 * @param reference: the Property to reference
	 */
	public void setReference(Property reference) {
		this.reference = reference;
	}
	
	public void output(PrintStream out) {output(out, "");}
	
	public void output(PrintStream out, String indent) {
		List<String> atts = new LinkedList<String>();
		if (key) {
			atts.add("key");
		}
		if (visited) {
			atts.add("visit");
		}
		if (desc != null) {
			atts.add("desc");
		}
		out.println(indent + "Property " + name + " : " + type.getName() + 
				" (" + Util.join(atts, ", ") + ")");
	}
}
